<template>
  <div class="platform-header">
    <div class="header-container">
      <div class="title-wrapper">
        <span class="title">国民体质监测数据采集与质量控制平台</span>
        <span class="light-effect"></span>
      </div>
    </div>
    <div class="timebody">
      <span class="time">{{ hours }}:{{ minutes }}:{{ seconds }}</span>
      <span class="date"> {{ month }}/{{ day }}/{{ year }}</span>
      <div class="right-menu">
        <el-button
          size="mini"
          @click.native="toProfile"
          circle
          class="my-icon profile-btn">
          <span class="profile-icon"></span>
        </el-button>
<!--        <el-button
          size="mini"
          @click.native="openSettings"
          circle
          class="my-icon settings-btn">
          <span class="settings-icon"></span>
        </el-button>-->
        <el-button
          size="mini"
          @click.native="logout"
          circle
          class="my-icon logout-btn">
          <span class="logout-icon" style="width: 51px"></span>
        </el-button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'PlatformHeader',
  data() {
    return {
      hours: "00",
      minutes: "00",
      seconds: "00",
      month: "00",
      day: "00",
      year: "0000"
    }
  },
  mounted() {
    this.updateTime();
    this.timer = setInterval(this.updateTime, 1000);
  },
  beforeDestroy() {
    clearInterval(this.timer);
  },
  methods: {
    updateTime() {
      const date = new Date();
      this.hours = date.getHours().toString().padStart(2, '0');
      this.minutes = date.getMinutes().toString().padStart(2, '0');
      this.seconds = date.getSeconds().toString().padStart(2, '0');
      this.month = (date.getMonth() + 1).toString().padStart(2, '0');
      this.day = date.getDate().toString().padStart(2, '0');
      this.year = date.getFullYear();
    },
    toProfile() {
      this.$router.push('/user/profile');
    },
    openSettings() {
      this.$store.dispatch('settings/changeSetting', {
        key: 'showSettings',
        value: true
      });
    },
    async logout() {
      this.$confirm('确定注销并退出系统吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        customClass: 'custom-confirm', // 添加自定义类名
      }).then(() => {
        this.$store.dispatch('LogOut').then(() => {
           location.href = '/index';
        })
      }).catch(() => {});
    }
  }
}
</script>

<style scoped lang="scss">
.platform-header {
  height: 72px;
  display: flex;
}

.header-container {
  position: relative;
  display: inline-block;
  letter-spacing: 8px;
  padding-right: 90px;
  border-bottom: 1px solid rgba(0, 175, 255, 0.5);
  height: 72px;
  line-height: 72px;
  font-size: 28px;
  box-sizing: border-box;
  font-weight: bold;
  background: url('../../assets/images/titleend.png') no-repeat 100% 100%;
  background-size: contain;
}

.title-wrapper {
  position: relative;
  display: inline-block;
  padding-left: 30px;
  overflow: hidden;
}

.title {
  position: relative;
  color: #e6e6e6;
  z-index: 2;
  text-shadow: 0 0 8px rgba(0, 175, 255, 0.3);
}

.light-effect {
  position: absolute;
  top: 0;
  left: 0;
  width: 120%;
  height: 100%;
  background: linear-gradient(
      90deg,
      transparent 0%,
      rgba(0, 175, 255, 0.1) 15%,
      rgba(0, 175, 255, 0.4) 35%,
      rgba(0, 175, 255, 0.6) 50%,
      rgba(0, 175, 255, 0.4) 65%,
      rgba(0, 175, 255, 0.1) 85%,
      transparent 100%
  );
  transform: translateX(-20%);
  animation: lightFlow 8s cubic-bezier(0.4, 0, 0.2, 1) infinite;
  z-index: 1;
  filter: blur(1.5px);
  opacity: 0.9;
}

@keyframes lightFlow {
  0% {
    transform: translateX(-20%);
    opacity: 0;
  }
  10% {
    opacity: 0.9;
  }
  90% {
    opacity: 0.9;
  }
  100% {
    transform: translateX(100%);
    opacity: 0;
  }
}

.timebody {
  height: 70px;
  box-sizing: border-box;
  line-height: 70px;
  border-bottom: 1px solid rgba(0, 175, 255, 0.5);
  flex: 1;
  margin-left: 20px;
  color: #e6e6e6;
  text-align: right;
  padding-right: 6px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 15px;
}

.time {
  font-size: 24px;
  font-weight: bold;
}

.date {
  font-size: 16px;
}

.right-menu {
  display: flex;
  align-items: center;
  gap: 8px;
}

.my-icon {
  padding: 6px !important;
  background: transparent;
  border: none;
  transition: all 0.3s;

  &:hover {
    background: rgba(0, 175, 255, 0.2) !important;
    transform: scale(1.1);
  }

  span {
    display: block;
    width: 34px;
    height:34px;
    background-size: 100% 100%;
    background-repeat: no-repeat;
    background-position: center;
  }
}

.profile-icon {
  background-image: url('../../assets/images/person.png');
}

.settings-icon {
  background-image: url('../../assets/images/layout.png');
}

.logout-icon {
  background-image: url('../../assets/images/layout.png');
}

/* 性能优化 */
.light-effect {
  will-change: transform, opacity;
  backface-visibility: hidden;
}
</style>
<style>

/* 自定义确认框样式 */



</style>
